<template>
  <ant-modal modalWidth="1000" modalHeight="600" :visible="open" :modal-title="formTitle" :adjust-size="true" :maskClosable="false"
    @cancel="cancel">
    <a-form-model ref="form" :model="form" :rules="rules" slot="content" layout="vertical">
      <a-row :gutter="32">
        <a-col :span="12">
          <a-form-model-item label="收款单号">
            <a-input v-model="form.payCode" placeholder="单号自动生成" :disabled='true' />
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="对账单号" prop="accountCode">
            <a-select placeholder="请选择对账单" v-model="form.accountCode" style="width: 100%" allow-clear>
              <a-select-option v-for="(d, index) in accountOptions" :key="index" :value="d.accountCode">{{
                d.accountCode }}</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span="12">
          <a-form-model-item label="客户" prop="customerId">
            <a-select placeholder="请选择客户" v-model="form.customerId" style="width: 100%" allow-clear>
              <a-select-option v-for="(d, index) in customerIdOptions" :key="index" :value="d.id">{{
                d.customerName }}</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <!-- <a-col :span="12">
          <a-form-model-item label="应收金额">
            <a-input v-model="form.hasAmount"  :disabled='true' />
          </a-form-model-item>
        </a-col> -->
        <a-col :span="12">
          <a-form-model-item label="收款金额" prop="payAmount">
            <a-input v-model="form.payAmount"  placeholder="请输入收款金额"/>
          </a-form-model-item>
        </a-col>
        <!-- <a-col :span="12">
          <a-form-model-item label="抹零金额" prop="zeroAmount">
            <a-input v-model="form.zeroAmount"  placeholder="请输入抹零金额"/>
          </a-form-model-item>
        </a-col> -->
        <a-col :span="12">
          <a-form-model-item label="收款日期" prop="payDate">
            <a-date-picker v-model="form.payDate" valueFormat="YYYY-MM-DD" :show-today="true" placeholder="选择日期"
              style="width: 100%" />
          </a-form-model-item>
        </a-col>
        <!-- <a-col :span="12">
          <a-form-model-item label="收款账户" prop="payAccount">
            <a-select placeholder="请选择收款账户" v-model="form.payAccount" style="width: 100%" allow-clear>
              <a-select-option v-for="(d, index) in payOptions" :key="index" :value="d.dictLabel">{{ d.dictLabel }}</a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col> -->
        <a-col :span="12">
          <a-form-model-item label="备注" prop="remark">
            <a-input v-model="form.remark" placeholder="请输入备注" />
          </a-form-model-item>
        </a-col>
      </a-row>
      
      <a-row>
        <a-col :span="24">
          <a-card :bordered="false">
            <advance-table :loading="loading" rowKey="id" size="middle" :columns="columns4" :data-source="form.paymentDetailList"
              :row-selection="{ selectedRowKeys: selectedAccountRowKeys, onChange: onAccountSelectChange }"
              :pagination="false" :bordered="true">
              <div class="table-operations" slot="button" style='margin-bottom:0px;'>
                  <div class="table_title">账户列表</div>
                  <a-button v-if="!disabled" type="primary" @click="handleAddPay"  >
                    <a-icon type="plus" />新增
                  </a-button>
                  <a-button type="danger" v-if="multipleAccount" @click="handleDelete">
                    <a-icon type="delete" />删除
                  </a-button>
                </div>
              <span slot="payAccount" slot-scope="{record}">
                <a-select placeholder="请选择收款账户" v-model="record.payAccount" style="width: 100%" allow-clear>
                  <a-select-option v-for="(d, index) in payOptions" :key="index" :value="d.dictLabel">{{ d.dictLabel }}</a-select-option>
                </a-select>
              </span>
              <span slot="payAmount" slot-scope="{record}">
                <a-input type='text' placeholder="请输入收款金额" v-model="record.payAmount" @change="amountChange"/>
              </span>
              <span slot="remark" slot-scope="{record}">
                <a-input type='text' placeholder="请输入备注" v-model="record.remark" />
              </span>
            </advance-table>
          </a-card>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="24">
          <a-card :bordered="false">
            <advance-table :loading="loading" rowKey="id" size="middle" :columns="columns3" :data-source="form.paymentBillList"
              :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
              :pagination="false" :bordered="true">
              <div class="table-operations" slot="button" style='margin-bottom:0px;'>
                  <div class="table_title">对账明细</div>
                  <a-button v-if="!disabled" type="primary" @click="handleAllocation"  >
                    自动分配
                  </a-button>
                  <a-button type="danger" v-if="multiple && !disabled" @click="handleDeleteRows">
                    <a-icon type="delete" />删除
                  </a-button>
                </div>
              <span slot="nopaySlot" slot-scope="{record}">
                {{ record.totalAmount - record.collectedAmount }}
              </span>
              <span slot="curSlot" slot-scope="{record}">
                <a-input type='text' placeholder="请输入本次结算金额" v-model="record.collectedAmount" @change="amountChange"/>
              </span>
            </advance-table>
          </a-card>
        </a-col>
      </a-row>
    </a-form-model>
    <template slot="footer">
      <a-button :disabled="disabled" @click="cancel">
        取消
      </a-button>
      <a-button type="primary" :disabled="disabled" @click="submitEdit(true)">
        保存
      </a-button>
    </template>
  </ant-modal>
</template>
<script>
import BizPaymentForm from './BizPaymentForm'
export default {
  ...BizPaymentForm
}
</script>
<style lang="less" scoped>
.table-operations,
body tr.ant-table-expanded-row:hover .table-operations {
  padding-bottom: 8px;
  text-align: right;
}

.table-operations {
  margin-bottom: 16px;
}

.table-operations>button,
.table-operations .ant-input-affix-wrapper {
  margin-right: 8px;
}

.table_title {
  float: left;
  padding-left: 8px;
  font-weight: 600;
  color: #222222;
  line-height: 30px;
}
</style>
